using System.IO;
using System.Reflection;

namespace System.Utility.Helper
{
	public class Reflection
	{
		public Reflection()
		{
		}

		public static object GetObjectValue<T>(T obj, string propertyName)
		{
			object value;
			if ((obj == null ? false : !string.IsNullOrEmpty(propertyName)))
			{
				PropertyInfo[] properties = obj.GetType().GetProperties();
				int num = (properties == null ? 0 : (int)properties.Length);
				int num1 = 0;
				while (num1 < num)
				{
					if (!string.Equals(properties[num1].Name, propertyName))
					{
						num1++;
					}
					else
					{
						value = properties[num1].GetValue(obj, null);
						return value;
					}
				}
				value = null;
			}
			else
			{
				value = null;
			}
			return value;
		}

		public static string GetResourceFile(string fileUrl)
		{
			string end;
			StreamReader streamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(fileUrl));
			try
			{
				end = streamReader.ReadToEnd();
			}
			finally
			{
				if (streamReader != null)
				{
					((IDisposable)streamReader).Dispose();
				}
			}
			return end;
		}

		public static void SettingObjectValue<T>(T obj, string propertyName, object value)
		{
			if ((obj == null || string.IsNullOrEmpty(propertyName) ? false : value != null))
			{
				PropertyInfo[] properties = obj.GetType().GetProperties();
				int num = (properties == null ? 0 : (int)properties.Length);
				int num1 = 0;
				while (num1 < num)
				{
					if (!string.Equals(properties[num1].Name, propertyName))
					{
						num1++;
					}
					else
					{
						properties[num1].SetValue(obj, value, null);
						break;
					}
				}
			}
		}		
	}
}